import { defineStore } from 'pinia';
import { getLesionData } from '@/api/setting/setting';
import type * as Type from '@/api/setting/setting.d';
import type { LesionDataState } from './type';

const useLesionData = defineStore('LesionData', {
    persist: true,
    state: (): LesionDataState => ({
        dataList: <Type.LesionDataItem[]>[]
    }),
    getters: {
        getList(state: LesionDataState): LesionDataState {
            return { ...state };
        }
    },
    actions: {
        setDataList(partial: Partial<LesionDataState>) {
            this.$patch(partial);
        },
        toJSON() {
            const result: {[key: string]: string} = {};
            this.$state.dataList.length !== 0 && this.$state.dataList.map(item => {
                result[item.value] = item.name;
            })
            return result;
        },
        async getDataList() {
            // 获取病灶数据
            const lesionParams = {
                page: 1,
                pageSize: 1000000,
            };
            const result = await getLesionData(lesionParams);
            result.data && result.data.list && this.setDataList({dataList: result.data.list});
            // const callResult = await this.toJSON();
            // return callResult;
        }
    }
})

export default useLesionData;